package com.lhnstart.learn.bases.innerclass;

/**
 * 匿名内部类
 *
 * @author lhn
 * @date 2023/07/18 10:35
 * @since 1.0.0
 **/
public class AnonymousInnerClass {

    public static void main(String[] args) {
        Outer04 outer04 = new Outer04();
        outer04.method();
    }

}

class Outer04{ // 外部类
    private int n1 = 10; // 属性

    public void method() { // 方法
        // 基于接口的匿名内部类
        IA tiger = new IA() {
            @Override
            public void cry() {
                System.out.println("老虎叫唤...");
            }
        };
        System.out.println(tiger.getClass());
        tiger.cry();

        // 基于类的匿名内部类
        Father father1 = new Father("jack");
        System.out.println(father1.getClass());
        Father father = new Father("jack") {
            @Override
            public void test() {
                super.test();
            }
        };
        System.out.println(father.getClass());

        animal animal = new animal() {
            @Override
            void eat() {
                System.out.println("吃东西...");
            }
        };
        animal.eat();
        System.out.println(animal.getClass());
    }
}

interface IA{ // 接口
    public void cry();
}

class Father{ // 外部其他类
    public Father(String name) { // 构造器
    }

    public void test() { // 方法

    }
}

abstract class animal {

    abstract void eat();

}